import java.util.Scanner;

/**
 * @Description: 实现一个简易的用户登陆
 * @Author Stark
 * @Date 2022/1/21 23:54
 **/
public class UserLogin {
    private static final String USERNAME = "stack";
    private static final String PASSWORD = "123456";
    
    public static void main(String[] args) {
        try{
            login();
            System.out.println("登陆成功");
        }catch (UserNameException | PasswordException e){
            e.printStackTrace();
        }
    }

    private static void login() throws UserNameException,PasswordException{
        System.out.println("请输入用户名：");
        Scanner scanner = new Scanner(System.in);
        String userName = scanner.next();
        if(!USERNAME.equals(userName)){
            //抛出用户名错误异常
            throw new UserNameException("用户名错误");
        }
        System.out.println("请输入密码：");
        String passWord = scanner.next();
        if(!PASSWORD.equals(passWord)){
            //抛出密码错误异常
            throw new PasswordException("密码错误");
        }
    }
}
//用户名异常
class UserNameException extends Exception{
    public UserNameException(String message) {
        super(message);
    }
}
//密码异常
class PasswordException extends Exception{
    public PasswordException(String message) {
        super(message);
    }
}
